class MyHashMap {

    private int nodes_length = 1024;

    private Node[] nodes = new Node[nodes_length];

    public MyHashMap() {

    }

    public void put(int key, int value) {
        int  index = Integer.hashCode(key) % nodes_length;
        Node node  = nodes[index];
        if (node == null) {
            nodes[index] = new Node(key, value);
        } else {
            node.addLast(key, value);
        }
    }


    public int get(int key) {
        Node node = nodes[Integer.hashCode(key) % nodes_length];
        if (node == null) {
            return -1;
        }
        return node.findByKey(key);
    }

    public void remove(int key) {
        int  index = Integer.hashCode(key) % nodes_length;
        Node node  = nodes[index];
        if (node != null) {
            if (node.key == key) {
                nodes[index] = node.next;
                return;
            }
            node.remove(key);
        }
    }
    static class Node {
        int  key;
        private int value;
        Node next;

        Node(int key, int value) {
            this.key = key;
            this.value = value;
        }

        void addLast(int key, int value) {
            if (key == this.key) {
                if (this.value != value) {
                    this.value = value;
                }
                return;
            }
            if (this.next == null) {
                this.next = new Node(key, value);
            } else {
                this.next.addLast(key, value);
            }
        }

        int findByKey(int key) {
            if (key == this.key) {
                return value;
            }
            Node next = this.next;
            if (next == null){
                return -1;
            }
            return next.findByKey(key);
        }

        void remove(int key) {
            Node next = this.next;
            if (next == null) {
                return;
            }
            if (next.key == key) {
                this.next = next.next;
            } else {
                next.remove(key);
            }
        }
    }
}


